package com.farm.farming.controller;

import com.farm.entity.PageResult;
import com.farm.entity.Result;
import com.farm.entity.StatusCode;
import com.farm.farming.pojo.Cust_permission;
import com.farm.farming.service.Cust_perimssionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/custPermission")
public class Cust_permissionController {

    @Autowired
    Cust_perimssionService cust_perimssionService;

    @PostMapping("/add")
    public Result add(@RequestBody Cust_permission cust_permission){

        cust_perimssionService.add(cust_permission);

        return new Result(true, StatusCode.OK,"添加权限完成");
    }

    @GetMapping("/deleteById")
    public Result deleteById(@RequestParam("id")Integer id){

        cust_perimssionService.delete(id);

        return new Result(true,StatusCode.OK,"删除权限完成");
    }

    @PostMapping("/update")
    public Result update(@RequestBody Cust_permission cust_permission){

        cust_perimssionService.update(cust_permission);

        return new Result(true,StatusCode.OK,"修改完成了");
    }

    @PostMapping("/findPage")
    public Result findPage(@RequestBody(required = false) Cust_permission cust_permission,
                           @RequestParam(value = "page",required = false,defaultValue = "0")Integer currentPage,
                           @RequestParam(value = "size",required = false,defaultValue = "10")Integer size){

        PageResult<Cust_permission> page = cust_perimssionService.findPage(cust_permission, currentPage, size);
        return new Result(true,StatusCode.OK,"分页查询完成",page);
    }
    @GetMapping("findByPermissionId")
    public Result findByPermissionId(@RequestParam("id")Integer id){

        Cust_permission permission = cust_perimssionService.findById(id);

        return new Result(true,StatusCode.OK,"查询权限完成",permission);
    }
}
